home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / programer2 / icon / Docs / Ipd113 next >
Text File  |  1990-07-22  |  18KB  |  661 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.                 The Icon Memory Monitoring System
  8.  
  9.                         Gregg M. Townsend
  10.     Department of Computer Science, The University of Arizona
  11.  
  12.  
  13.  
  14. Introduction
  15.  
  16.    The Icon memory monitoring system (``MemMon'') provides tools
  17. for displaying Icon's allocated data regions [1].  It consists of
  18. instrumentation that produces allocation history files (Appendix
  19. C) and visualization programs that convert allocation history
  20. files to displays that show the sizes, types, and locations of
  21. strings as they are allocated.  The garbage collection process is
  22. shown in detail.
  23.  
  24.    There are several visualization programs; most of them are
  25. specific to the University of Arizona environment.  Appendix A
  26. describes mmps, a program for producing displays that can be
  27. printed on any PostScript printer.
  28.  
  29.    An allocation history file is produced by setting the environ-
  30. ment variable MEMMON to the name of the desired file.  No change
  31. in the Icon program is necessary and the production of an alloca-
  32. tion history file does not change program behavior (except for
  33. increasing run time somewhat).  On Unix systems, if the value of
  34. the MEMMON environment variable begins with `|', the rest of the
  35. value is interpreted as a shell command into which the history is
  36. piped.
  37.  
  38. The_Display
  39.  
  40.    Icon has two primary allocated data regions: a string region
  41. and a block region.  On implementations that support region
  42. expansion [2], there is also a static region.  The display shows
  43. the regions as if they were contiguous, which they are on imple-
  44. mentations that support region expansion.  The static region, if
  45. it exists, comes first, followed by the string and block regions.
  46. The choice of regions that are displayed can be specified.  By
  47. default, the static region is not displayed, but the string and
  48. block regions are.
  49.  
  50.    Color distinguishes the various uses of memory, and by infer-
  51. ence the region boundaries.  A legend at the top of the screen
  52. gives the meaning of each color.  Default colors can be changed
  53. by providing an alternate specification file.
  54.  
  55.    Colors and boundaries are set at allocation time; subsequent
  56. changes are not reflected until garbage collection occurs.  For
  57. example, a string constructed in pieces may not show as a con-
  58. catenated whole.
  59.  
  60.    The line above the color legend gives the program status at
  61.  
  62.  
  63.  
  64. IPD113a                       - 1 -                 March 6, 1990
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. the left, the name of the allocation history file in the center,
  74. and storage information at the right, such as
  75.  
  76.         60480 + 25600 + 51200  (0+0+1+0)
  77.  
  78. The first three numbers give the current sizes (in bytes) of the
  79. static, string, and block regions respectively.  The ordering
  80. reflects that of the display.  The first three numbers in
  81. parentheses count the garbage collections caused by exhaustion of
  82. the regions, with the fourth number counting garbage collections
  83. initiated by calls to collect(0).
  84.  
  85. Garbage_Collection
  86.  
  87.    The garbage collection process is shown in detail by producing
  88. snapshots at critical points.  The first comes at the beginning
  89. of garbage collection, and indicates the reason the garbage col-
  90. lection is required.
  91.  
  92.    The next snapshot follows the marking phase.  Active data is
  93. dark gray; the remaining blocks are garbage to be discarded.
  94.  
  95.    The next snapshot shows the marked (active) data in color,
  96. before compaction, with the garbage painted black.  This is the
  97. inverse of the previous display.
  98.  
  99.    The last snapshot shows the state of memory at the end of gar-
  100. bage collection, after compacting the active data.  All garbage
  101. is gone, and the string region shows a single unbroken string.
  102. At this point the image may be rescaled to handle region expan-
  103. sion.
  104.  
  105.    Alien blocks (such as I/O buffers) in the static region are
  106. not subject to marking or garbage collection and instead remain
  107. on constant display throughout.  Obsolete co-expression blocks
  108. are freed during the marking phase, but they are displayed in a
  109. manner similar to other blocks so that their disappearance can be
  110. noted.
  111.  
  112. The_Programmer's_Interface
  113.  
  114.    Three built-in Icon functions write to the allocation history
  115. to control a subsequent MemMon run.
  116.  
  117.    mmpause(s) generates a snapshot similar to those during gar-
  118. bage collection; the name comes from its effect on interactive
  119. visualization programs, which pause at this point.  s, if sup-
  120. plied, is displayed to identify the pause.  The default for s is
  121. "programmed pause".
  122.  
  123.    mmshow(x,s) redraws x if x is in the managed memory region.
  124. This can be used to identify one or more particular data objects
  125. on the display.  s determines the color of x:
  126.  
  127.  
  128.  
  129.  
  130. IPD113a                       - 2 -                 March 6, 1990
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.         "w"  white
  140.         "g"  gray
  141.         "b"  black
  142.         "h"  highlight: blinking white and black
  143.         "r"  redraw in normal color (the default)
  144.  
  145. The altered display persists until the next garbage collection.
  146. If x is outside the managed memory region, no action is taken.
  147.  
  148.    mmout(s) writes s (without further interpretation) as a
  149. separate line in the history file.  This can be used to insert
  150. comments (beginning with #).
  151.  
  152.    All three functions return the null value.
  153.  
  154. Accessing_the_Monitoring_System
  155.  
  156.    The mmps program is built in the v8/src/memmon subdirectory of
  157. the Icon distribution.  Instructions for running mmps appear in
  158. Appendix B.
  159.  
  160.    That subdirectory also includes some sample color specifica-
  161. tion files as well as code for building interactive visualization
  162. programs.  Further information about this appears in [3].
  163.  
  164.  
  165. References
  166.  
  167.  
  168. 1.   R. E. Griswold and M. T. Griswold, The Implementation of the
  169.      Icon Programming Language, Princeton University Press, 1986.
  170.  
  171. 2.   R. E. Griswold, Supplementary Information for the
  172.      Implementation of Version 7.9 of Icon, The Univ. of Arizona
  173.      Icon Project Document IPD51d, 1989.
  174.  
  175. 3.   G. M. Townsend, Notes on MemMon Internals, The Univ. of
  176.      Arizona Icon Project Document IPD97a, 1989.
  177.  
  178. 4.   Encapsulated PostScript File Format, Version 1.2, Adobe
  179.      Systems Incorporated, 1987.
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196. IPD113a                       - 3 -                 March 6, 1990
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.                       Appendix A:  Running mmps
  206.  
  207.  
  208.  
  209.    mmps generates Encapsulated Postscript [4] displays of Icon
  210. memory.  One or more images are produced under control of command
  211. options.  Output files are Encapsulated PostScript documents
  212. suitable either for direct printing or for incorporation into
  213. other documents.  The output includes full color information,
  214. though most PostScript devices print only the black-and-white
  215. equivalent.
  216.  
  217.    The default image is 468 x 624 points, or 6.5" x 8.7",
  218. centered on a standard page.  One line represents 1872 bytes of
  219. memory.  Smaller or larger images can be specified; larger ones
  220. are reduced to fit within the above bounds.
  221.  
  222. Command_format
  223.  
  224.    mmps  [ options ]  [ file ]
  225.  
  226. Options
  227.  
  228.      -r regionsDisplay the indicated memory regions:
  229.              f   static (fixed) region
  230.              s   string region
  231.              b   block region
  232.              The default is -r sb.
  233.  
  234.      -p when Produce a snapshot at the indicated points:
  235.              f   memory full (beginning of garbage collection)
  236.              g   showing garbage remaining after marking
  237.              a   showing unmarked, active blocks after marking
  238.              c   after compaction (end of garbage collection)
  239.              p   explicit mmpause() calls
  240.              d   (``done'') when the program terminates
  241.              n   never
  242.              The default is -p fgacpd.
  243.  
  244.      -m      Run through the marking phase even when not pausing
  245.              to display the results.  Normally, marking is
  246.              bypassed if neither of -p ga is selected.
  247.  
  248.      -g n    Skip to the end of the nth garbage collection before
  249.              displaying anything.
  250.  
  251.      -q n    Quit after completing the nth garbage collection.
  252.  
  253.      -Q n    Quit after the nth snapshot.
  254.  
  255.      -b n    Make each horizontal point represent n bytes of
  256.              memory.  The default is 4.
  257.  
  258.  
  259.  
  260.  
  261.  
  262. IPD113a                       - 4 -                 March 6, 1990
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.      -w n    Set the display width to n points.  The default is
  272.              468.
  273.  
  274.      -h n    Set the display height to n points.  The default is
  275.              624.
  276.  
  277.      -L n    Make the legend and status lines n points high.  -L
  278.              0 eliminates the header entirely.  The default is
  279.              11.
  280.  
  281.      -M n    Limit the memory region lines to a maximum of n
  282.              points in height.  The default is 20.
  283.  
  284.      -t titleSet the display title.  The default is the
  285.              allocation history file name.
  286.  
  287.      -c file Use an alternate color specification file (see
  288.              Appendix B).
  289.  
  290.      -S n    Set the PostScript screen frequency to n lines per
  291.              inch.
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328. IPD113a                       - 5 -                 March 6, 1990
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.               Appendix B: Color Specification Files
  338.  
  339.  
  340.  
  341.    A color specification file can be used to change some or all
  342. of the colors produced by mmps.
  343.  
  344.    The environment variable MMCOLORS can be used to name a file
  345. containing color specifications.  mmps reads this file and uses
  346. it to override the normal defaults.  Then, if a file is passed by
  347. the -c option of mmps, it overrides both the built-in defaults
  348. and anything from an MMCOLORS file.
  349.  
  350.    Lines in a color specification file contain two whitespace-
  351. separated fields, a label and a value, optionally followed by
  352. comments.  Blank lines are ignored, as are lines beginning with #
  353. .  For example:
  354.  
  355.  
  356.         #  change the colors for sets
  357.         set    657  light purple for set headers
  358.         selem  637  medium putple for set elements
  359.  
  360.  
  361.  
  362.    The label field matches either one of the types shown in the
  363. legend or one of these additional keywords:
  364.  
  365.         background  background
  366.         bsep        block separator
  367.         ssep        string separator
  368.         marked      marked block
  369.         unmarked    unmarked block (when showing active data)
  370.         status      status message
  371.         prompt      prompt message
  372.         title       title field
  373.         regions     region sizes
  374.  
  375.  
  376.    The value field is a set of three octal digits specifying a
  377. color.  The digits control the red, green, and blue color
  378. components in that order, with a range of 0 to 7 for each.  A
  379. value of 0 is dark and a value of 7 is light.  For example, 070
  380. is green (0% red + 100% green + 0% blue) and 405 is purple (4/7
  381. red + 5/7 blue).  Unfortunately, the final colors are somewhat
  382. device-dependent because of different responses to the same
  383. specification.
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394. IPD113a                       - 6 -                 March 6, 1990
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.               Appendix C: Allocation History Files
  404.  
  405.  
  406.  
  407.    An allocation history file is composed of printable characters
  408. forming a sequence of commands that trace interpreter actions
  409. related to memory management.  This section describes the overall
  410. structure of an allocation history file, using terms and commands
  411. that are described later in detail.
  412.  
  413.    An allocation history file begins with a refresh sequence,
  414. which completely specifies the memory layout at a particular
  415. instant.  The initial refresh sequence gives a snapshot of memory
  416. just before the start of execution.  Within a refresh sequence,
  417. item commands enumerate all the objects within the three regions,
  418. as if they are being placed, in order, into initially empty
  419. regions.
  420.  
  421.    After the initial refresh sequence, the rest of the file
  422. contains any number of the following components, in any order:
  423.      item commands
  424.      interaction commands
  425.      garbage collection sequences
  426.  
  427.    Item commands, when outside other sequences, record new
  428. allocations of memory.
  429.  
  430.    Interaction commands are generated by programmed calls to
  431. mmshow() and mmpause().
  432.  
  433.    A garbage collection sequence begins with a marking sequence,
  434. in which item commands identify live objects.  The marking
  435. sequence is followed by a new refresh sequence giving the memory
  436. configuration after compaction.  Then, a final marker signals the
  437. end of garbage collection.
  438.  
  439.    Comment and verification commands may appear at any point in
  440. the file.
  441.  
  442. Command_Format
  443.  
  444.    A command has several components:
  445.      [addr+] [len] cmd [etc]
  446.  
  447.      addr is an optional address, given as a distance from the
  448.           start of a region.  If the address is omitted, the
  449.           current end of the region is assumed.  An address is
  450.           always followed immediately by + .
  451.  
  452.      len  is a length.  If a length is needed by a command, but
  453.           none is supplied, then the most recent length specified
  454.           for that particular command is used.
  455.  
  456.  
  457.  
  458.  
  459.  
  460. IPD113a                       - 7 -                 March 6, 1990
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.      cmd  is a single character identifying the command.
  470.  
  471.      etc  is additional information needed by a few particular
  472.           commands.
  473.  
  474.    Addresses and lengths are nonnegative decimal numbers.  In the
  475. string region, the unit of measurement is a character; in the
  476. static and block regions, it is specified in the refresh sequence
  477. and usually is 4 bytes.
  478.  
  479.    Whitespace between commands is optional; whitespace within a
  480. command is allowed only in etc data.
  481.  
  482. Item_Commands
  483.  
  484.    Item commands identify individual allocated objects.  The
  485. meaning of an item command depends on its context.  Within a
  486. refresh sequence, item commands enumerate the existing
  487. allocations.  Within a marking sequence, item commands mark live
  488. objects.  Otherwise, item commands announce new allocations.
  489.  
  490.    Except during marking, string and block region item commands
  491. do not include addresses.  Addresses may be obtained by totaling
  492. the allocations made since the beginning of the last refresh
  493. sequence.
  494.  
  495.    The item commands for the block region are:
  496.      [addr+] [len] c     cset
  497.      [addr+] [len] e     table element trapped variable
  498.      [addr+] [len] E     external block
  499.      [addr+] [len] f     file block
  500.      [addr+] [len] L     list header
  501.      [addr+] [len] l     list element
  502.      [addr+] [len] R     record
  503.      [addr+] [len] r     real number
  504.      [addr+] [len] S     set header
  505.      [addr+] [len] s     set element
  506.      [addr+] [len] T     table header
  507.      [addr+] [len] t     table element
  508.      [addr+] [len] u     substring trapped variable
  509.      [addr+] [len] x     co-expression refresh block
  510.  
  511.    The string item command is:
  512.      [addr+] [len] "     string
  513.  
  514.    The static region item commands always include an address.
  515. They are:
  516.      addr + [len] X co-expression block
  517.      addr + [len] A alien block
  518.  
  519. Refresh_Sequence_Commands
  520.      [units] < static-region_string-region_block-region
  521.             Begin a refresh sequence.  Each region specification
  522.             has the form
  523.  
  524.  
  525.  
  526. IPD113a                       - 8 -                 March 6, 1990
  527.  
  528.  
  529.  
  530.  
  531.                  base_: used_/ max
  532.             where base is the beginning address of the region,
  533.             used is the amount of memory used, and max is the
  534.             amount of memory allocated to the region.  For the
  535.             static region, the used value is meaningless, and
  536.             base and max are zero with fixed-region versions of
  537.             Icon.  All values in this command are given in bytes.
  538.             The units parameter, if present, gives the size of a
  539.             unit of measurement for other commands referencing
  540.             the static and block regions.  If the units parameter
  541.             is absent, the unit of measurement is four bytes.
  542.      >    End a refresh sequence
  543.  
  544. Verification_Command
  545.      = static-region_block-region_string-region
  546.             Region specifications are the same as for the <
  547.             command.  This command provides no new information
  548.             but confirms the accumulated memory usage after a
  549.             series of allocations.
  550.  
  551. Garbage_Collection_Commands
  552.      n_{  Start a garbage collection and begin the marking phase
  553.             n indicates the reason for the collection:
  554.                  0    collect(0) call
  555.                  1    static region
  556.                  2    string region
  557.                  3    block region
  558.      }    End the marking phase
  559.      !    End garbage collection
  560.  
  561. Interaction_Commands
  562.      ; string
  563.             Pause (produce a snapshot) and display string, which
  564.             includes all characters up to a newline.  This
  565.             command is generated by a programmed mmpause(string)
  566.             call.
  567.      addr_+ len_$ c_t    highlight a string
  568.  
  569.      addr_+ len_% c_t    highlight a block
  570.  
  571.      addr_+ len_Y c_t    highlight a static object
  572.             Highlight commands are generated by programmed
  573.             mmshow(x,s) calls.  c is the first character of the
  574.             argument string s, indicating the kind of
  575.             highlighting desired.  t identifies the type of the
  576.             object being highlighted by giving the character used
  577.             for an allocation command of that type.
  578.  
  579. Comment_Command
  580.      # comment
  581.             All characters following the #, up to a newline, are
  582.             ignored.
  583.  
  584. Example
  585.  
  586.    Here is a small, contrived program that builds a list of
  587. strings, then inserts the strings in a set:
  588.  
  589.  
  590.  
  591.  
  592. IPD113a                       - 9 -                 March 6, 1990
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.         procedure main ()
  602.            l := list ()
  603.            every put (l, string (-50 to 50))
  604.            s := set ()
  605.            every insert (s, !l)
  606.            end
  607.  
  608.  
  609.    Here is the corresponding history file:
  610.  
  611.         4< 234076:60000/60000 294080:0/65024 359104:0/65024
  612.         2+2666F2670+2050A4722+2A4726+4A4732+8A4742+256A5000+10000X
  613.         0"
  614.         >
  615.         = 234076:60000/60000 294080:0/65024 359104:0/65024
  616.         5L23lLl3"""""""""l""""""""l""""""""31l""""""""""""43l""""2"""""""""1""
  617.         """61l"""""2""""""""""""""""""""""87l"""""""""""""""""""14S10h5sssssss
  618.         sssssssssssssssssssssssssssssssssshsssssssssssssssssssssssssssssssssss
  619.         sssss18hssssssssssssssssssss
  620.         = 234076:60000/60000 294080:233/65024 359104:3524/65024
  621.  
  622.  
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658. IPD113a                      - 10 -                 March 6, 1990
  659.  
  660.  
  661.